﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UtilsExtensionsAndHelpers.Extensions
{
    public static class IEnumerableExtensions
    {
        /// <summary>
        /// Shortcut to items.ToList().ForEach(action);
        /// </summary>
        public static void Each<T>(this IEnumerable<T> items, Action<T> action)
        {
            items.ToList().ForEach(action);
        }

        /// <summary>
        /// Shortcut to !items.Contains(value);
        /// </summary>
        public static bool DoesntContain<T>(this IEnumerable<T> items, T value)
        {
            return !items.Contains(value);
        }

        /// <summary>
        /// Shortcut to !items.Any();
        /// </summary>
        public static bool None<T>(this IEnumerable<T> items)
        {
            return !items.Any();
        }

        /// <summary>
        /// Shortcut to !items.Any();
        /// </summary>
        public static bool None<T>(this IEnumerable<T> items, Predicate<T> predicate)
        {
            return !items.Any(i => predicate(i));
        }

        /// <summary>
        /// Shortcut to String.Join(separator, items.Select(o => o.ToString()));
        /// </summary>
        public static string JoinToString<T>(this IEnumerable<T> items, string separator)
        {
            return String.Join(separator, items.Select(o => o.ToString()).ToArray());
        }
    }
}
